<?php
namespace Home\Controller;
use Think\Controller;
class BaseController extends Controller {
    public $site_info;
    public $default_info;
    public static $user_info;
    public function __construct()
    {
        parent::__construct();
        $this->site_info = array(
        	'app_id' => '111',
            'title' => '帮帮购',
            'site_info' => '帮帮购,帮你选择购物',
            'logo' => '/sources/pic/favicon.ico',
            'route_base' => '/index.php/home',
            'post_num' => '11',
            'view_num' => '4',
        );
        $this->default_info = array(
            'default_head' => '/sources/pic/2.png',
        );
    }
    /**
     * 用户信息
     */
    public function getUserInfo($uid=0)
    {
    	if(empty($uid))
    		$uid = '当前用户id';
    	if(self::$user_info[$uid]) return self::$user_info[$uid];
        $result = array(
            'user_id'=>234,
            'nick'=>'张三',
            'user_pic'=>'/sources/pic/20141026211304_80638.jpg',
        	'post_data'=>array(
	        	'like'=>44,           //喜欢(收藏)数
	        	'laud'=>22,           //点赞数
	        	'comment_count'=>33,  //用户评论数
	        	'post_count'=>31, 	  //帖子数量
	        	'accept_count'=>1,    //被采纳数
        	)
        );
        self::$user_info[$uid] = $result;
        return $result;
    }

    /**
     * 判断当前用户是否为作者
     */
    public function isAuthor($uid)
    {
	    $user_info = $this->getUserInfo();
	    
	    if($user_info.user_id != $uid)
	    {
	    	return false;
	    }
	    return true;
    }

    /**
     * 判断当前用户是否为作者
     */
    public function failAuthRedirect($uid, $err_msg='权限不够 ', $err_url='Index/index')
    {
	    if($this->isAuthor($uid))
	    {
	    	if(empty($err_msg)) return false;
	    	$err_url = U($err_url);
	    	$this->error($err_msg, $err_url);
	    }
	    return true;
    }
}
